﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("BE")]
namespace DAL.DataFramework
{
    public class DataTransactionsDAL<T>:PropertiesHelper,IDisposable
    {
        string CreateGUID = "E0412D21-78E8-4045-9D57-4B6E41FD9A3A";
        string UpdateGUID = "CB8A7A17-38A3-4B2B-90FE-34EF754061A4";
        string DeleteGUID = "F9928929-B6C1-4407-AB92-D7F36A650DEA";
        string SelectGUID = "465F74D1-18B0-4EDF-90F9-7C7649C61F22";
        internal List<T> Select(int iDataTransactionId, string sName, string sGUID, int iConnectionId, string sProcedureName)
        {
            try
            {
                List<T> result = new List<T>();

                result = new GenericList<T>().GetAGenelicListOf(
                    DAL.Gateway.DataAccessGateway.TraerDataTable(SelectGUID,
                    iDataTransactionId,
                    sName,
                    sGUID,
                    iConnectionId,
                    sProcedureName)).ToList<T>();

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("DataTransactionsDAL - Select - ", ex);
            }
        }
        internal T Create(string sName, int iConnectionId, string sProcedureName)
        {
            try
            {
                T result = Activator.CreateInstance<T>();

                result = new GenericList<T>().GetAGenelicListOf(
                    DAL.Gateway.DataAccessGateway.TraerDataTable(CreateGUID,
                    sName,
                    iConnectionId,
                    sProcedureName)).Single<T>();

                return result;
            }
            catch(Exception ex)
            {
                throw new Exception("DataTransactionsDAL - Create - ",ex);
            }
        }
        internal T Update(int iDataTransactionId, string sName, string sGUID, int iConnectionId, string sProcedureName)
        {
            try
            {
                T result = Activator.CreateInstance<T>();
                result = new GenericList<T>().GetAGenelicListOf(
                   DAL.Gateway.DataAccessGateway.TraerDataTable(UpdateGUID,
                   iDataTransactionId,
                   sName,
                   sGUID,
                   iConnectionId,
                   sProcedureName)).Single<T>();

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("DataTransactionsDAL - Update - ", ex);
            }
        }
        internal int Delete(int iDataTransactionId)
        {
            try
            {
                int result = 0;

                result =
                    DAL.Gateway.DataAccessGateway.Ejecutar(DeleteGUID,iDataTransactionId);

                return result;
            }
            catch(Exception ex)
            {
                throw new Exception("DataTransactionsDAL - Delete - ",ex);
            }
        }
        public void Dispose()
        {
        }
    }
}
